package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.RoleView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface RoleViewMapper extends JpaRepository<RoleView, Long>, JpaSpecificationExecutor<RoleView> {

    @Query(value = "select p from RoleView p where p.applicationId = :appId and p.roleCode = :roleCode")
    RoleView findByRoleCode(long appId, String roleCode);

    @Query(value = "select p from RoleView p where p.applicationId = :appId and p.roleName = :roleName")
    Collection<RoleView> findListByRoleName(long appId, String roleName);

    @Query(value = "select p from RoleView p where p.applicationId = :appId and p.enabled")
    Collection<RoleView> findListByAvailable(long appId);

    Page<RoleView> findAll(Specification<RoleView> specification, Pageable pageable);
}
